# -*- coding: utf-8 -*- 
"""
Project: automation-api-project
Creator: jinsheng
Create time: 2021-11-22 09:23
IDE: PyCharm
Introduction: 设备模拟量mysql造数据
"""
from common.mysqlDataOperate import OperateMysql
import random
from threading import Thread

l = [x for x in range(100000) if x % 1000 == 0]


# op = OperateMysql()


def insert(start):
    op = OperateMysql()
    for j in range(start + 1, start + 1001):
        for i in range(1, 101):
            device_id = str(10000000 + j)
            analog_name = f'测试模拟量_{device_id}_' + str(i)
            analog_code = f'test_analog_{device_id}_' + str(i)
            ratio = round(random.uniform(1.0, 10.0), 2)
            analog_identifier = random.randint(1, 10)
            up_limit = round(random.uniform(100.0, 300.0), 2)
            low_limit = round(random.uniform(50.0, 99.0), 2)
            upper_limit = round(random.uniform(200.0, 400.0), 2)
            lower_limit = round(random.uniform(1.0, 50.0), 2)
            sql = f"""INSERT INTO device_center.device_analog_rela
            VALUES
                (
                    NULL,
                    '{device_id}',
                    '{analog_name}',
                    '{analog_code}',
                    NULL,
                    {ratio},
                    '{analog_identifier}',
                    {up_limit},
                    {low_limit},
                    {upper_limit},
                    {lower_limit},
                    NULL,
                    'test',
                    'jins',
                    '2021-11-22 08:00:00',
                    'jins',
                '2021-11-12 09:00:00',
                0) """
            op.batch_excute(sql)
        op.commit()
    op.close()


threads = []
for arrayval in l:
    threads.append(Thread(target=insert, args=(arrayval,)))
    threads[-1].start()
for thread in threads:
    thread.join()
